package com.直方图内最大的矩形状;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int n = sc.nextInt();
		int array[] = new int[n];
		for(int i=0;i<n;i++) {
			array[i]=sc.nextInt();
		}
		System.out.println(countMaxArea(array));
	}
	public static int countMaxArea(int[]array) {
		int max=0;
		for(int i=0;i<array.length;i++) {
			int min = Integer.MAX_VALUE;
			for(int j=i;j>=0;j--) {
				min = Math.min(min,array[j]);
				max = Math.max(max, (j-i+1)*min);
			}
		}
		return max;
	}

}
